package com.wkr.controller;

import com.wkr.bean.PageBean;
import com.wkr.bean.product;
import com.wkr.service.testService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public class testController {

    @Autowired
    testService ts;

    @RequestMapping("/add")
    public void toAdd() {
        product p = new product();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
        String data = simpleDateFormat.format(new Date());
        p.setpName(data);
        ts.save(p);
    }

    @RequestMapping("/find")
    @ResponseBody
    public Map find(int currentPage, int MaxSize) {
        Map result = new HashMap();
        PageBean pageBean = ts.find(currentPage, MaxSize);
        result.put("result", pageBean);
        return result;
    }

    @Scheduled(cron = "0/1 * * * * ?")//每隔1秒隔行一次
    public void findone() {
        product p =  ts.findone();
        System.out.println(p.getpName());
        System.out.println("------------------");
    }
}
